-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider expires_in when clear expired tokens with StaleRecordsCleaner #1690
base: main
Are you sure you want to change the base?
Consider expires_in when clear expired tokens with StaleRecordsCleaner #1690
Conversation
@@ -28,6 +28,7 @@ def clean_expired(ttl) | |||
@base_scope | |||
.where.not(expires_in: nil) | |||
.where(table[:created_at].lt(Time.current - ttl)) | |||
.where(table[:created_at] + table[:expires_in].lt(Time.current)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't we have an issues with timezones? I believe we're storing UTC and should use the same value regardless of configured application timezone, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I believe .where(table[:created_at].lt(Time.current - ttl))
does the same 🤔 By calculating ttl from configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nbulaj it does the same only if you rely on the ttl from configuration. If in your app your are creating tokens with different expiration times you need to consider expires_in
and perform calculations with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @fredplante , you mean tokens created manually with some custom TTL, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nbulaj Yes, that's what I meant. For info, we had to create a custom task. Here is what we're doing (we use PG):
DoorkeeperExtensions::AccessToken
.where(refresh_token: nil)
.where.not(expires_in: nil)
.where("? > (oauth_access_tokens.created_at + INTERVAL '1 second' * expires_in)", Time.current)
.in_batches(&:delete_all)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, we have some time SQL math as well https://github.com/doorkeeper-gem/doorkeeper/blob/a02cd99a304b01ca1bf529ca9d6bba5e7ff67f00/lib/doorkeeper/models/concerns/expiration_time_sql_math.rb
BTW MR sounds correct to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Can we please rebase and update a changelog? 🙏
Thanks!
Hey @nbulaj @fredplante thanks for checking! |
Presumably fixes #1688.
Consider expires_in when comparing with Time.current.